<template>
  <a-drawer
    :maskClosable="false"
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    :visible="visible">
    <erp-meeting-reservation-form ref="realForm" @ok="submitCallback" @canceled="handleMeetingCancel" :disabled="disableSubmit" normal></erp-meeting-reservation-form>
    <div class="drawer-footer">
      <a-popconfirm title="确定关闭弹窗吗?" @confirm="handleCancel" :getPopupContainer="(node) =>  node.parentNode">
        <a-button style="margin-bottom: 0;">关闭</a-button>
      </a-popconfirm>
      <a-popconfirm title="确定取消会议吗？" @confirm="meetingCancel" :getPopupContainer="(node) =>  node.parentNode">
        <a-button v-if="isEdit" style="margin-bottom: 0;">取消</a-button>
      </a-popconfirm>
      <a-button v-if="!disableSubmit" @click="handleOk" type="primary" style="margin-bottom: 0;">保存</a-button>
    </div>
  </a-drawer>
</template>

<script>
import ErpMeetingReservationForm from './ErpMeetingReservationForm'

export default {
  name: 'ErpMeetingReservationModal',
  components: {
    ErpMeetingReservationForm
  },
  data () {
    return {
      title: '操作',
      width: 800,
      visible: false,
      disableSubmit: false,
      isEdit:false
    }
  },
  methods: {
    add (record, roomInfo) {
      this.visible = true
      this.isEdit = false
      this.$nextTick(() => {
        this.$refs.realForm.add(record, roomInfo);
      })
    },
    edit (record, roomInfo) {
      this.visible = true
      this.isEdit = true
      this.$nextTick(() => {
        this.$refs.realForm.edit(record, roomInfo);
      });
    },
    close () {
      this.$emit('close');
      this.visible = false;
    },
    submitCallback() {
      this.$emit('ok');
      this.visible = false;
    },
    handleOk () {
      this.$refs.realForm.submitForm();
    },
    handleCancel () {
      this.close()
    },
    // 取消会议
    meetingCancel(){
      this.$refs.realForm.cancel();
    },
    // 取消会议监听
    handleMeetingCancel(isCanceled){
      if(isCanceled===1){
        this.$emit('ok');
        this.close()
      }
    }
  }
}
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
  .drawer-footer{
    position: absolute;
    bottom: -8px;
    width: 100%;
    border-top: 1px solid #e8e8e8;
    padding: 10px 16px;
    text-align: right;
    left: 0;
    background: #fff;
    border-radius: 0 0 2px 2px;
  }
</style>
